home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / inn1.000 / inn1.4sec-linux-src.tar / inn / lib / lock.c < prev    next >
C/C++ Source or Header  |  1992-04-03  |  1KB  |  74 lines

  1. /*  $Revision: 1.8 $
  2. **
  3. **  InterNetNews replacement for C news system locking.
  4. */
  5. #include <stdio.h>
  6.  
  7. static char    COMMAND[] = "ctlinnd %s Expire process %ld";
  8. static int    IsLocked;
  9.  
  10.  
  11. /*
  12. **  C News debugging function.
  13. /* ARGSUSED */
  14. void
  15. lockdebug(state)
  16.     int        state;
  17. {
  18. }
  19.  
  20.  
  21. /*
  22. **  Lock the news system by telling the server to throttle input.
  23. */
  24. void
  25. newslock()
  26. {
  27.     char    buff[72];
  28.     int        i;
  29.  
  30.     (void)sprintf(buff, COMMAND, "throttle", (long)getpid());
  31.     i = system(buff) >> 8;
  32.     if (i)
  33.     error("Can't lock");
  34.     IsLocked = 1;
  35. }
  36.  
  37.  
  38. /*
  39. **  Unlock the system and reload the files.
  40. */
  41. void
  42. newsunlock()
  43. {
  44.     char    buff[72];
  45.     int        i;
  46.  
  47.     if (IsLocked) {
  48.     (void)sprintf(buff, COMMAND, "go", (long)getpid());
  49.     i = system(buff) >> 8;
  50.     if (i)
  51.         error("Can't reload");
  52.     (void)sprintf(buff, "ctlinnd go");
  53.     i = system(buff) >> 8;
  54.     if (i)
  55.         error("Can't unlock");
  56.     IsLocked = 0;
  57.     }
  58. }
  59.  
  60.  
  61. /*
  62. **  Print an error message, then unlock the system.
  63. */
  64. void
  65. errunlock(text, arg)
  66.     char    *text;
  67.     char    *arg;
  68. {
  69.     warning(text, arg);
  70.     newsunlock();
  71.     exit(1);
  72.     /* NOTREACHED */
  73. }
  74.